//
//  SISSContractRightShowCell.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/12/27.
//  Copyright © 2018 优房网. All rights reserved.
//

#import "SISSContractRightShowCell.h"

@interface SISSContractRightShowCell ()

/// Label
@property (weak, nonatomic) UILabel *label;
/// rightLabel
@property (weak, nonatomic) UILabel *rightLabel;
/* bottomLine */
@property (weak, nonatomic) UIView *bottomLine;

@end
@implementation SISSContractRightShowCell

- (void)setContractModel:(SISSContractModel *)contractModel {
    [super setContractModel:contractModel];
    
    if (contractModel.leftStr.length > 0 && [[contractModel.leftStr substringToIndex:1] isEqualToString:@"*"]) {
        NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:contractModel.leftStr];
        [attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,1)];
        self.label.attributedText = attributedStr;
    } else {
        self.label.text = contractModel.leftStr;
    }
    
    self.rightLabel.text = contractModel.rightStr;
}

#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    UILabel *label = [[UILabel alloc] init];
    label.numberOfLines = 0;
    label.textColor = MAIN_TEXT_COLOR;
    label.font = [UIFont systemFontOfSize:16];
    label.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:label];
    self.label = label;
    
    UILabel *rightLabel = [[UILabel alloc] init];
    rightLabel.numberOfLines = 0;
    rightLabel.textColor = MAIN_TEXT_COLOR;
    rightLabel.font = [UIFont systemFontOfSize:16];
    rightLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:rightLabel];
    self.rightLabel = rightLabel;
    
    UIView *bottomLine = [[UIView alloc] init];
    bottomLine.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:bottomLine];
    self.bottomLine = bottomLine;
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    CGFloat margin = 8.0;
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(weakSelf.contentView).offset(1.5 * margin);
    }];
    
    [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView).offset(20 * margin);
        make.top.equalTo(weakSelf.label);
        make.right.equalTo(weakSelf.contentView).offset(-margin);
    }];
    
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.rightLabel.mas_bottom).offset(1.5 * margin);
        make.left.right.bottom.equalTo(weakSelf.contentView);
        make.height.mas_equalTo(1);
    }];
}


@end
